<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\business;



use App\Dao\UserCashDao;
use App\Middleware\User\UserMiddleware;

use App\Request\business\User\UserCashRequest;
use App\Service\Business\UserBusinessCashService;
use App\Service\business\UserCashService;
use App\Request\Business\User\GetCashInfoRequest;
use App\Request\Business\User\CashWithdrawalRequest;
use App\Request\Business\User\GetCashOneRequest;
use App\Request\Business\User\CheckPwdRequest;
use App\Service\ConfigService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Middleware;

/**
 * 提现控制器
 *
 * @AutoController()
 * @Middleware(UserMiddleware::class)
 * @author eug(1196070838@qq.com)
 * @package App\Controller\admin
 */
class UserCashController extends Controller
{
    /**
     * @Inject
     * @var UserCashDao
     */
    private $dao;

    /**
     * @Inject
     * @var UserBusinessCashService
     */
    private $service;

    /**
     * 获取提现记录
     *
     * @param GetCashInfoRequest $request
     */
    public function get_cash_info(GetCashInfoRequest $request)
    {
        $params = $request->all();

        isset($params['start_time']) && $params['start_time'] = (string)$params['start_time'];

        $result = $this->service->getCashInfo($params);

        $this->success($result);
    }

    /**
     * 新增提现
     *
     * @param CashWithdrawalRequest $request
     */
    public function cash_withdrawal(CashWithdrawalRequest $request)
    {
        $params = $request->all();

        isset($params['bank_id']) && $params['bank_id'] = (int)$params['bank_id'];
        isset($params['amount']) && $params['amount'] = (int)$params['amount'];

        $result = $this->service->cashWithdrawal($params);

        $this->success($result);
    }

    /**
     * 获取一条提现信息
     *
     * @param GetCashOneRequest $request
     */
    public function get_cash_one(GetCashOneRequest $request)
    {
        $params = $request->all();

        isset($params['id']) && $params['id'] = (int)$params['id'];

        $result = $this->service->getCashOne($params);

        $this->success($result);
    }

    /**
     * 取消提现
     *
     */
    public function delete()
    {
        $cash_id = (int)$this->request->input('cash_id', 0);
        if ($cash_id === 0) $this->error();

        $this->dao->delete($cash_id);

        $this->success();
    }

    /**
     * 检查密码
     *
     * @param CheckPwdRequest $request
     */
    public function check_pwd(CheckPwdRequest $request)
    {
        $params = $request->all();

        isset($params['pwd']) && $params['pwd'] = (string)$params['pwd'];

        $result = $this->service->checkPwd($params);

        $this->success($result);
    }

    /**
     * 获取收款码
     *
     */
    public function get_qrcode()
    {
        $result = $this->service->getQrCode();

        $this->success($result);
    }
}